package com.wxx.utils;

import com.wxx.contance.Contance;
import org.slf4j.MDC;

import java.util.UUID;

/**
 * @author: wxx
 * @date: 2024/6/5 11:18
 * @description todo 描述信息
 */
public class TraceIdUtil {

    /**
     * 生成tracdLogid
     *
     * @return
     */
    public static String getTraceLogId() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    /**
     * 设置 traceLogid
     *
     * @param traceLogid
     * @return
     */
    public static String setTraceLogid(String traceLogid) {
        if (traceLogid == null) {
            traceLogid = getTraceLogId();
        }
        MDC.put(Contance.TRACE_ID, traceLogid);
        return traceLogid;
    }

    /**
     * 清空
     */
    public static void clear() {
        MDC.clear();
    }

}
